object DoWhileDemo extends App {

  val maxRenewals = 2
  var renewCount = 0
  var wantToRenew = false

  do{
    wantToRenew = if (renewCount == 0) true else scala.util.Random.nextBoolean()

    if (wantToRenew && renewCount < maxRenewals){
      renewCount +=1
      println(s"借阅成功，当前借阅次数：$renewCount/$maxRenewals")
    }else if (renewCount>=maxRenewals){
      println(s"已达到最大续借次数（$maxRenewals 次），无法继续续借")
      wantToRenew = false
    } else {
      println("用户选择不续借")
    }
  } while (wantToRenew && renewCount < maxRenewals)
      println (s"\n 续借流程结束，共续借 $renewCount 次")
}
